// uuidUtils.js
const { v4: uuidv4 } = require('uuid');

function generateShortUUID() {
    const uuid = uuidv4(); // 生成标准 UUID
    const bytes = Buffer.from(uuid.replace(/-/g, ''), 'hex');
    const encoded = bytes.toString('base64');
    const urlSafeEncoded = encoded.replace(/\+/g, '').replace(/\//g, '').replace(/=+$/, '');
    return urlSafeEncoded;
}

function generateTimestampBasedID() {
    const timestamp = Date.now().toString(36);
    const randomSuffix = Math.random().toString(36).substring(2, 6);
    return `${timestamp}${randomSuffix}`;
}

module.exports = { generateShortUUID, generateTimestampBasedID };
